/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.kungkhies.persistence.entities;

import java.io.Serializable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author clayton
 */
@Entity 
@Table(name = "polyhole")
@XmlRootElement
@NamedQueries(
{
    @NamedQuery(name = "Polyhole.findAll", query = "SELECT p FROM Polyhole p"),
    @NamedQuery(name = "Polyhole.findByKungkhieId", query = "SELECT p FROM Polyhole p WHERE p.polyholePK.kungkhieId = :kungkhieId"),
    @NamedQuery(name = "Polyhole.findByPolyholeId", query = "SELECT p FROM Polyhole p WHERE p.polyholePK.polyholeId = :polyholeId"),
    @NamedQuery(name = "Polyhole.findByKnodeId", query = "SELECT p FROM Polyhole p WHERE p.polyholePK.knodeId = :knodeId")
})
public class Polyhole implements Serializable 
{
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected PolyholePK polyholePK;
    @JoinColumns(
    {
        @JoinColumn(name = "kungkhie_id", referencedColumnName = "kungkhie_id", insertable = false, updatable = false),
        @JoinColumn(name = "knode_id", referencedColumnName = "knode_id", insertable = false, updatable = false)
    })
    @ManyToOne(optional = false)
    private KungkhieKnode kungkhieKnode;

    public Polyhole()
    {
    }

    public Polyhole(PolyholePK polyholePK)
    {
        this.polyholePK = polyholePK;
    }

    public Polyhole(long kungkhieId, long polyholeId, long knodeId)
    {
        this.polyholePK = new PolyholePK(kungkhieId, polyholeId, knodeId);
    }

    public PolyholePK getPolyholePK()
    {
        return polyholePK;
    }

    public void setPolyholePK(PolyholePK polyholePK)
    {
        this.polyholePK = polyholePK;
    }

    public KungkhieKnode getKungkhieKnode()
    {
        return kungkhieKnode;
    }

    public void setKungkhieKnode(KungkhieKnode kungkhieKnode)
    {
        this.kungkhieKnode = kungkhieKnode;
    }

    @Override
    public int hashCode()
    {
        int hash = 0;
        hash += (polyholePK != null ? polyholePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object)
    {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Polyhole))
        {
            return false;
        }
        Polyhole other = (Polyhole) object;
        if ((this.polyholePK == null && other.polyholePK != null) || (this.polyholePK != null && !this.polyholePK.equals(other.polyholePK)))
        {
            return false;
        }
        return true;
    }

    @Override
    public String toString()
    {
        return "com.kungkhies.persistence.entities.Polyhole[ polyholePK=" + polyholePK + " ]";
    }

}
